        TITL DAI FIRMWARE 3EB26-3EC44  V1.1
        ORG   :EB26
*
*
*
************
* L - LOOK *
************
*
LOOKK   MVI   C,:03     Nr datablocks allowed
        CALL  ADART     Scan keyb, display char,
 REM get addresses on stack
        LHLD  PCSAV     Get addr next instr
        XCHG            in DE
        MOV   A,C       Get nr of inputs done
        CPI   :03       No addr given?
        MVI   A,:00
        CZ    L3E179    No addr: Check CR given
        CNZ   L3E178    Else: store windows and
 REM start program
        STA   SAVA      Set Look flag
        XCHG            Addr next instr in HL
        JMP   L3E344    Init RST 0
*
* SET LOOK WINDOWS. START LOOK:
*
* Entry: A=0, C=3 minus number of fields read.
* Exit:  Input 2 fields: A,C = 0.
*        Input 3 fields: A,C = FF. DE corrupted.
*        B preserved, HL corrupted.
*
L3E178  DCR   C
        DCR   C
        JZ    ERROR     Error if only 1 addr given
        POP   H         Get returnaddr from stack
        XTHL            haddr window in HL
        SHLD  HADTRW    Save haddr
        POP   H         Return addr from stack
        XTHL            laddr window in HL
        SHLD  LADTRW    Save laddr
        INR   C
        RZ              Ready if only window given
 REM
* If startaddress given:
 REM
        DCR   A         A=FF
        POP   H         Get returnaddr from stack
        POP   D         Get startaddr program in DE
        PCHL            Return
*
******************************
* GO/LOOK: CHECK FOR CAR.RET *
******************************
*
* Entry: B: Character to be checked.
* Exit:  AF corrupted, BCDEHL preserved.
*
L3E179  MOV   A,B       Get last char typed in
        SUI   :0D
        JNZ   ERROR     Error if not CR
        RET
*
*
*********************
* RESTART 0 (RST 0) *
*********************
*
* The RST 0 function is used to operate 'LOOK'.
* Via a timer 1 interrupt, RST 0 is called.
* The vectoraddress #EB5D must have been
* initialised by a Z2 or Z3 command.
*
* On entry, HL and PC are on stack (see 0000
* -0007).
*
L3E180  PUSH  PSW
        NOP
        LDA   DEVICE    Get stored EI/DI
        SUI   :FB
        JZ    L3E181    Jump if EI stored
        MVI   A,:01     Else: Set int. mask
        STA   TICC8     for timer 1 only
 REM
* Save all registers in RAM area:
 REM
L3E181  EI
        POP   PSW       Restore PSW
        POP   H         Restore HL
        SHLD  HLSAV     Save HL
        PUSH  PSW
        PUSH  B
        PUSH  D
        POP   H
        SHLD  DESAV     Save DE
        POP   H
        SHLD  BCSAV     Save BC
        POP   H
        SHLD  AFSAV     Save PSW
        POP   H
        SHLD  PCSAV     Save PC
 REM
* Check if PC points to 004D-4E:
 REM
        LXI   D,:FFB3
        DAD   D
        XCHG            DE=PC+FFB3 (=PC-004D)
        LHLD  IADR      Get addr where to continue
        MOV   A,D
        ORA   A
        JNZ   L3E182    Jump if out of interrupt
 REM routine
        ORA   E
        CPI   :04
        JC    L3E193    Jump if PC = 004D-4E
 REM
* Put returnaddress on stack if current instruction
* is a RST or a CALL instruction:
 REM
L3E182  MVI   B,:C7
        MOV   A,M       Get instr code of next instr
        CPI   :CD
        JZ    L3E183    Jump if it is a CALL
        ANA   B         ) Check if it is a RST
        CMP   B         )
        JZ    L3E184    Then jump
        MOV   A,M       Get instr code
        ANA   B         ) Check if it is a
        CPI   :C4       ) conditional CALL
        JNZ   L3E185    Jump if not
L3E183  INX   H
        INX   H
L3E184  INX   H
        XTHL            Addr next instr on stack
 REM if it was a RST or CALL
 REM
* Check if current instruction is inside window:
 REM
L3E185  LXI   H,:0000
        DAD   SP
        SHLD  SPSAV     Save SP
        CALL  L3E238    Exchange bytes in reg. save
 REM area
        LHLD  IADR      Get addr current instr
        XCHG            in DE
        LHLD  LADTRW    Get laddr window
        CALL  L3E194    Compare DE-HL
        JM    L3E186    Jump if addr outside window
        LHLD  HADTRW    Get haddr window
        CALL  L3E194    Compare DE-HL
        JNC   L3E186    Jump if addr outside window
 REM
* Print registers contents if address inside window:
 REM
        CALL  LCRLF     Print car.ret
        LXI   D,IADR    Startaddr reg. save area
        LXI   H,L3E405  Startaddr symbol table
        CALL  L3E234    Print reg. contents
L3E186  CALL  BREAK     Scan for Break pressed;
 REM evt run Break
        LHLD  PCSAV     Get addr next instr
 REM
* Disable UT to trace itself:
* Entry from init, RST0.
* HL is address where to continu.
 REM
L3E187  MVI   A,:EA
        CMP   H         Check if hibyte = EA
        JNZ   L3E188    Jump if not
        MVI   A,:0D
        CMP   L         Check if lobyte = 0D
        JZ    ERROR     Then go to Error
 REM
* Check if next opcode is RST or EI/DI:
 REM
L3E188  DI
        SHLD  IADR      Save addr current instr
        LXI   D,SAVH
        XCHG
        SHLD  PCSAV     Set addr next instr = 004C
        XCHG
        MOV   A,M       Get opcode of instr
        ANI   :C7
        CPI   :C7
        JZ    L3E192    Jump if RST
        LDA   CHOPRT    Get int. mask
        CALL  L3E345    Store it in TIC; set A=0
        STA   TICC9     Reset timer 1 (trap
 REM immediate)
        MOV   A,M       Get opcode of instr
        ANI   :F7       ) Check if EI or DI
        SUI   :F3       )
        MOV   A,M       Get inst code
        XCHG            HL = #004C
        MVI   M,:FB     Load EI in #004C
        MVI   C,:03     3 instr bytes to be loaded
 REM into #004D-F
        JZ    L3E191    Jump if instr is EI/DI
 REM
* Load next instruction into 004D-4F:
 REM
L3E189  LDAX  D         Get instr code
L3E190  INX   H
        MOV   M,A       Store it in #004D-F
        INX   D
        DCR   C
        JNZ   L3E189    Next byte of instr
*
* Run LOOK: Register contents:
*
*   If 'normal instr': 004C:    EI.
*                      004D-4F: Next instruction.
*
*   If RST *:          004C-4D: RST */ data **.
*                      004E:    RST 0.
*
*   If EI/DI:          004C:    EI.
*                      004D:    NOP.
*                      004E-50: Next instruction.
*                         This may cause problems,
*                         because 0050 is LOOK init
*                         flag.
*
        CALL  L3E343    XRA A; LXI H,#0050
        CMP   M         Check look flag
        MOV   M,A       Reset flag
        JZ    L3E196    If not Look init: restore
 REM CPU reg; cont on (005D/E)=
 REM 004C
        JMP   L3E221    Else: Restore TIC/GICC/
 REM CPU reg/int.mask and 'GO'
 REM to (005D/E)=004C
 REM
* If instruction is EI or DI:
 REM
L3E191  STA   DEVICE    Store EI/DI instr
        XRA   A
        JMP   L3E190    Load 00 in #004D, next instr
 REM in 004E-0050
 REM
* If a RST instruction:
 REM
L3E192  XCHG            HL=004C
        MVI   C,:02     Only 2-byte instruction
        MVI   A,:C7
        STA   SAVD      Set (004E)=#C7 (=RST0)
        JMP   L3E346    RST*/data ** in 004C/D
 REM
* If PC points to 004D-004E:
 REM
L3E193  DAD   D         Set HL=0000-0001. This may
 REM cause re-entry problems due
 REM to stack manipulation
        SHLD  PCSAV     Save addr next instr (pnts
 REM to RST0)
        JMP   L3E185  
*
*
*
        UNL
ADART   EQU   :EB07
PCSAV   EQU   :005D
SAVA    EQU   :0050
L3E344  EQU   :EF35
ERROR   EQU   :EA62
HADTRW  EQU   :0048
LADTRW  EQU   :004A
DEVICE  EQU   :0047
TICC8   EQU   :FFF8
HLSAV   EQU   :0059
DESAV   EQU   :0057
BCSAV   EQU   :0055
AFSAV   EQU   :0053
IADR    EQU   :0051
SPSAV   EQU   :005B
L3E238  EQU   :EDE7
L3E194  EQU   :EC45
LCRLF   EQU   :ED3A
L3E405  EQU   :EE9C
L3E234  EQU   :EE44
BREAK   EQU   :EEC2
SAVH    EQU   :004C
CHOPRT  EQU   :005F
L3E345  EQU   :EF3E
TICC9   EQU   :FFF9
L3E343  EQU   :EF30
L3E196  EQU   :EC63
L3E221  EQU   :ED9C
SAVD    EQU   :004E
L3E346  EQU   :EF44
        LST
        END
